<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use DB;
class Grow extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'grow';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        //
        // echo '这里是grow.php';
        // $this->error('hello world');
        $today = date('Y-m-d');
        $tasks = DB::table('tasks')->where('enddate','>=',$today)->get();

         foreach ($tasks as $t) {

          // $data = DB::table('grows')->where(['uid'=>$t->uid,'pid'=>$t->pid,'paytime'=>$today])->first();
          //如果三个条件同时成立,并且查出一条数据,说明已经得到收益,不会再次得到收益
          if(!DB::table('grows')->where(['uid'=>$t->uid,'pid'=>$t->pid,'paytime'=>$today])->first()){

            $row = [];
            $row['uid'] = $t->uid;
            $row['pid'] = $t->pid;
            $row['title'] = $t->title;
            $row['amount'] = $t->amount;
            $row['paytime'] = $today;
            DB::table('grows')->insert($row);
          }
         }
    }
}
